package com.grj.community.all.advice;

import org.springframework.web.bind.annotation.ExceptionHandler;
import org.springframework.web.bind.annotation.RestControllerAdvice;

import java.util.HashMap;
import java.util.Map;

/**
 * @author 14505
 */
@RestControllerAdvice
public class GlobalAdvice {

    @ExceptionHandler(Exception.class)
    public Map<Object, Object> exceptionHandler(Exception e) {
        Map<Object, Object> map = new HashMap<>();
        map.put("code", 500);
        map.put("msg", e.getMessage());
        if (e.getMessage() == null) {
            map.put("msg", e.getCause().getMessage());
        }
        return map;
    }
}
